
import json
import yaml
import pandas as pd
from typing import Dict, Any

def load_test_data(file_path: str) -> Dict[str, Any]:
    """加载测试数据"""
    if file_path.endswith('.json'):
        with open(file_path, 'r', encoding='utf-8') as f:
            return json.load(f)
    elif file_path.endswith('.yaml') or file_path.endswith('.yml'):
        with open(file_path, 'r', encoding='utf-8') as f:
            return yaml.safe_load(f)
    elif file_path.endswith('.xlsx'):
        return pd.read_excel(file_path).to_dict('records')

# 数据驱动示例
@pytest.mark.parametrize("login_data", load_test_data("data/login_cases.json"))
def test_data_driven_login(api_client, login_data):
    response = api_client.post("/login", json=login_data)
    expected_status = login_data.get("expected_status", 200)
    assert response.status_code == expected_status